<template>
  <div class="home-container">
    <div class="content-wrapper">
      <!-- 广告轮播 -->
      <div class="ad-carousel">
        <el-carousel height="300px" :interval="4000">
          <el-carousel-item v-for="item in carouselItems" :key="item">
            <div class="carousel-item" @click="handleAdClick(item)">
              <img :src="item" class="carousel-image" :alt="item">
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>

      <!-- 主要内容区 -->
      <div class="article-content">
        <div class="intro-text">
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;发现完美礼物的秘密：让每一次送礼都成为惊喜！
          在这个快节奏的时代，送礼似乎变成了一项“任务”，而不是一份心意。你是否曾经在挑选礼物时感到无从下手？
          是否在朋友的生日、节日聚会或纪念日时，常常陷入“送什么好”的困惑中？今天，让我们一起探索更多的礼物灵感，
          创造出更多温暖的瞬间吧！记住，最好的礼物是你用心挑选的那一份。
        </div>

        <!-- 商品列表 -->
        <div class="product-list">
          <el-row :gutter="20">
            <el-col :span="8" v-for="product in products" :key="product.id">
              <el-card class="product-card" shadow="hover">
                <img :src="product.image" class="product-image">
                <div class="product-info">
                  <h3 class="product-title" v-html="product.title"></h3>
                  <p class="product-desc">{{ product.description }}</p>
                  <div class="product-price">¥{{ product.price }}</div>
                  <el-button type="primary" @click="viewProduct(product.id)">
                    查看详情
                  </el-button>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {getAllApi} from "@/api/ProductApi";

export default {
  name: 'HomePage',
  data() {
    return {
      products: [],
      carouselItems: [
          "https://webtest858.oss-cn-guangzhou.aliyuncs.com/images/jd.jpg",
          "https://webtest858.oss-cn-guangzhou.aliyuncs.com/images/tb.jpg",
          "https://webtest858.oss-cn-guangzhou.aliyuncs.com/images/pdd.jpg"
      ]
    }
  },
  mounted() {
    getAllApi().then(res=>{
      if (res.data.code==1){
        this.products = res.data.data.records
      }
    })
    this.products = this.products.filter(item => item.status == 1)


  }
}
</script>

<script setup>

import {useRouter} from 'vue-router'

const router = useRouter()

const viewProduct = (id) => {
  console.log("商品id"+id)
  router.push(`/product/${id}`)
}

const handleAdClick = (link) => {
  window.open(link, '_blank')
}


</script>

<style scoped>
.home-container {
  background-color: #f5f5f5;
}

.content-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.article-header {
  text-align: center;
  margin-bottom: 30px;
}

.article-header h1 {
  font-size: 28px;
  color: #333;
  margin-bottom: 10px;
}

.article-meta {
  color: #666;
  font-size: 14px;
}

.intro-text {
  font-size: 16px;
  line-height: 1.6;
  color: #666;
  margin-bottom: 30px;
  text-align: justify;
}

.product-list {
  margin-top: 30px;
}

.product-card {
  margin-bottom: 20px;
  transition: transform 0.3s ease;
}

.product-card:hover {
  transform: translateY(-5px);
}

.product-info {
  padding: 20px;
}

.product-title {
  font-size: 18px;
  margin: 0 0 10px;
  color: #333;
}

.product-desc {
  font-size: 14px;
  color: #666;
  margin-bottom: 15px;
  line-height: 1.4;
}

.product-price {
  font-size: 20px;
  color: #ff6b6b;
  font-weight: bold;
  margin-bottom: 15px;
}

.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.ad-carousel {
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.carousel-item {
  position: relative;
  cursor: pointer;
  height: 100%;
}

.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.carousel-item:hover .carousel-image {
  transform: scale(1.05);
}

.carousel-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  font-size: 16px;
}
</style> 